﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SosaAnalysisModule.Data;
using SosaAnalysisModule.Modules;
using SosaAnalysisModule;
using System.IO;


namespace SosaAnalysisModuleTest
{
    [TestClass]
    public class ImageBuilderUnitTest : ImageBuilder
    {
        [TestMethod]
        public void TestLargestPoints()
        {
            String path = Directory.GetCurrentDirectory();
            string token = "SosaAnalysisModule\\";
            int length = path.IndexOf(token) + token.Length;
            path = path.Substring(0, length - 1) + "SosaAnalysisModuleTest\\testFinal.csv";

            Group[] groupData = new Group[1];
            groupData[0] = new Group("test","1");
            groupData[0].data = new List<SosaData>();
            groupData[0].data.Add(SOSAFileReader.CreateSosaData(path));

            double[] sample = ImageBuilder.LargestPoints(groupData);

            Assert.AreEqual(5, sample[0]);
            Assert.AreEqual(5, sample[1]);
        }
        [TestMethod]
        public void TestAverage()
        {
            String path = Directory.GetCurrentDirectory();
            string token = "SosaAnalysisModule\\";
            int length = path.IndexOf(token) + token.Length;
            string path1 = path.Substring(0, length - 1) + "SosaAnalysisModuleTest\\testFinal.csv";
            string path2 = path.Substring(0, length - 1) + "SosaAnalysisModuleTest\\testFinal2.csv";

            Group testGroup = new Group("test", "1");
            testGroup.data = new List<SosaData>();
            testGroup.data.Add(SOSAFileReader.CreateSosaData(path1));
            testGroup.data.Add(SOSAFileReader.CreateSosaData(path2));

            System.Windows.Point[] sample = ImageBuilder.Average(testGroup);
            Assert.AreEqual(-7.5, sample[0].X);
            Assert.AreEqual(7.5, sample[0].Y);
            Assert.AreEqual(7.5, sample[1].X);
            Assert.AreEqual(-7.5, sample[1].Y);
            Assert.AreEqual(7.5, sample[2].X);
            Assert.AreEqual(7.5, sample[2].Y);
            Assert.AreEqual(-7.5, sample[3].X);
            Assert.AreEqual(-7.5, sample[3].Y);
        }

    }
}
